package com.etime.shycourse.orde.services.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shycourse.dao.CourseMapper;
import com.etime.shycourse.orde.dao.OrderdetailMapper;
import com.etime.shycourse.orde.dao.OrdersMapper;
import com.etime.shycourse.orde.dto.SysOrderDetailsDto;
import com.etime.shycourse.orde.pojo.Orders;
import com.etime.shycourse.orde.services.interfaces.OrderdetailServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wb
 * @since 2022-01-10
 */
@Service
public class OrderdetailServiceImpl implements OrderdetailServices {
    @Autowired
    OrdersMapper mapper;
    @Autowired
    OrderdetailMapper orderdetailMapper;
    @Autowired
    CourseMapper courseMapper;

    /**
     * 后台功能，一般由管理员或者财务人员有权限查看
     * 查询 订单列表；
     * 订单详情查询数据  可选填条件订单号 用户id 下单时间 分页
     *
     * @param orders orderno, 可选填条件订单号"
     *               orderuserid  可选填选择条件用户id
     *               orderpayment  支付方式
     *               orderstate, value = "订单状态,
     *               pagenum, value = "第几页"),
     *               pagesize, value = "每页多少行,
     *               ordercreatetimeOne  可选填选择条件用户下单时间 开始"),
     *               ordercreatetimeTwo  可选填选择条件用户下单时间 结束"),
     * @return Page<SysOrderDetailsDto>
     */
    @Override
    public Page<SysOrderDetailsDto> selectOrderDetailsListPageBys(Orders orders, Long pagenum, Long pagesize) {
        // 返回数据
        Page<SysOrderDetailsDto> pages;
        /**
         * 当前端没有传分页数据时 就使用 page默认的值
         * pagesize = 1L
         * size = 10L;
         * */
        Page<SysOrderDetailsDto> page;
        if (pagenum != null & pagesize != null) {
            page = new Page<> (pagenum, pagesize);
        } else {
            page = new Page<> ();
        }
        // 订单分页 查询
        if (orders == null) {
            pages = orderdetailMapper.selectOrderDetailsPageBys (page, null, null, null, null, null, null);
        } else {
            pages = orderdetailMapper.selectOrderDetailsPageBys (page, orders.getOrderno (), orders.getOrderuserid (), orders.getOrderstate (), orders.getOrderpayment (), orders.getOrdercreatetimeOne (), orders.getOrdercreatetimeTwo ());
        }
        return pages;
    }
}
